package cn.bonoon.kernel.support.services.handler;

import javax.persistence.EntityManager;

import cn.bonoon.kernel.events.OperateEvent;
import cn.bonoon.kernel.support.entities.Persistable;

public class OperateDeleteHandler implements OperateHandler{
	private final DeleteHandler deleteHandler;
	
	public OperateDeleteHandler(DeleteHandler deleteHandler) {
		this.deleteHandler = deleteHandler;
	}
	
	@Override
	public Object handler(EntityManager entityManager, OperateEvent event, Persistable entity) {
		deleteHandler.handler(entityManager, event, entity);
		return "删除实体:" + entity.getId();
	}
	
	@Override
	public MultiOperateHandlerExecuter handler(final EntityManager entityManager, final OperateEvent event) {
		return new MultiOperateHandlerExecuter(){

			@Override
			public MultiOperateHandlerExecuter addParameter(Persistable entity) {
				deleteHandler.handler(entityManager, event, entity);
				return this;
			}

			@Override
			public void execute() { }
			
		};
//		E entity = null;
//		String sids = "删除实体:";
//			for(int i = 0; i < entitys.length; i++){
//				entity = entitys[i];
//				deleteHandler.handler(service, event, entity);
//				sids = entity.getId() + ",";
//			}
//		return sids;
	}
}
